home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7416 < prev    next >
Encoding:
Text File  |  1996-08-05  |  908 b   |  28 lines

  1. Path: ccshst05.cs.uoguelph.ca!ccshst01!thay
  2. From: thay@uoguelph.ca (Toby K Hay)
  3. Newsgroups: comp.lang.c
  4. Subject: Q: How to assign structures?
  5. Date: 26 Feb 1996 12:56:30 GMT
  6. Organization: University of Guelph
  7. Message-ID: <4gsalu$dll@ccshst05.cs.uoguelph.ca>
  8. NNTP-Posting-Host: ccshst01.cs.uoguelph.ca
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. I need to assign values to structures in one array from structures in 
  12. another array - in essence I'm copying the whole structure from one array 
  13. to the other.  Can I use simple assignment like this:
  14.  
  15. struct StructName {
  16.     int     IVal;
  17.     float    FVal;}
  18.  
  19. struct StructName Array1[5], Array2[5];
  20. . . .
  21. for (i=0;i<5;i++) Array1[i] = Array2[i];
  22. . . .
  23. And if not that, can I use memcpy() and sizeof() to do the assignment:
  24.  
  25. for (i=0;i<5;i++) memcpy(&Array2[i],&Array1[i],sizeof(struct StructName));
  26. Or do I have to assign each element of the structure?
  27. Toby Hay    thay@uoguelph.ca
  28.